<template>
	<view class="currentPage">
		<view class="wrapper">
			<view class="content">
				<view class="close-btn">
					<image src="/static/icon/dynamic/close.png" @tap='close'></image>
				</view>
				<view class="release-content">
					<textarea value="" placeholder="这一刻的想法..." v-model="value" />
					<up-load-img @returnImgUrl='getImgUrl'></up-load-img>
				</view>
				<view class="select">
					<view class="select-item" v-for="(item,index) in selectItem" :key='index' @tap='chooseRegion'>
						<view class="" style="display: flex;align-items: center;">
							<image :src="item.icon" mode=""></image>
							<text>{{item.label}}</text>
						</view>
						<view class="right-arrow"></view>
					</view>
				</view>
				<button type="default" class="release-btn" @tap='releaseDynamic'>发表</button>
			</view>
		</view>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	import upLoadImg from "@/components/upLoadImg.vue"
	export default {
		components: {
			upLoadImg
		},
		data() {
			return {
				selectItem: [{
					icon: '/static/icon/dynamic/dinwei.png',
					label: '所在位置'
				}],
				value: "",
				imgUrl: []
			};
		},
		mounted() {
			uni.$on('chooseRegion', (res, index) => {
				console.log(res)
				if (index == 1) {
					this.selectItem[0].label = res.poiName
				} else if (index > 1) {
					this.selectItem[0].label = res.address
				}
			})
		},
		methods: {
			getImgUrl(e) {
				console.log(e)
				this.imgUrl.push(e)
				
			},
			releaseDynamic() {

				let obj = {
					content: this.value,
					imgUrl: JSON.stringify(this.imgUrl),
					location: this.selectItem[0].label || ""
				}
				console.log(obj)
				this.$api.releaseDynamic(obj).then(res => {
					console.log(res)
					if (res.data.code == 1) {
						this.$refs.uToast.show({
							title: res.data.msg,
							type: 'success',
							position: "top",
							duration: 1500
						})
						setTimeout(() => {
							this.close()
						}, 1500)
					}

				})
			},
			chooseRegion() {
				uni.navigateTo({
					url: '/pages/chooseRegion/chooseRegion',
					fail: (err) => {
						console.log(err)
					}
				})
			},
			close() {
				//未发布关闭时删除上传内容
				// uniCloud.callFunction({
				// 	name:'delFile',
				// 	data:{
				// 		fileList:this.imgUrl
				// 	}
				// }).then(res=>{
				// 	console.log('云函数回调',res)
				// })
				uni.navigateBack({
					delta: 1
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.currentPage {
		height: 100vh;
		// overflow: hidden;
		// background: rgb(245, 246, 250);
		background-color: #FFFFFF;
	}

	.wrapper {
		background-color: #FFFFFF;

	}

	.content {
		// border: 1px solid;

		height: 100%;
		width: 92%;
		margin: auto;
		padding: 20rpx 0;

		.close-btn {
			text-align: right;
			margin-top: 100rpx;
			padding: 20rpx 0;

			image {
				height: 40rpx;
				width: 40rpx;

			}
		}

		.release-content {
			margin: 30rpx;

			// border: 1px solid;
			textarea {
				padding: 15rpx;
				border: 1px solid rgba(128, 128, 128, .2);
				border-radius: 10rpx;
				margin: 20rpx auto;
				height: 150rpx;
				width: 590rpx;
				font-size: 26rpx;
			}
		}

	}

	.select {
		// height: 500rpx;
		// border: 1px solid;
		margin: 150rpx 30rpx;

		.select-item {
			font-size: 30rpx;
			padding: 30rpx 0;
			border-top: 1px solid rgba(128, 128, 128, .2);
			border-bottom: 1px solid rgba(128, 128, 128, .2);
			display: flex;
			align-items: center;
			justify-content: space-between;

			image {
				height: 40rpx;
				width: 40rpx;
				margin-right: 30rpx;
				// border: 1px solid;
			}

			.right-arrow {
				height: 20rpx;
				width: 20rpx;
				border-top: 1px solid rgba(128, 128, 128, .3);
				border-right: 1px solid rgba(128, 128, 128, .3);
				transform: rotateZ(45deg);
			}
		}
	}

	.release-btn {
		border: none;
		outline: none;
		background-color: #2979FF;
		color: #FFFFFF;
		// position: fixed;
		// bottom: 20rpx;
		// left: 200rpx;
		// right: 200rpx;
	}
</style>
